package com.example.artwindow.tool;

import com.example.artwindow.constants.QiNiuProperties;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


public class QiNiuOSTool {
	public static String Os(String name, MultipartFile io){
		//构造一个带指定 Region 对象的配置类
		UploadManager uploadManager = new UploadManager(new Configuration());
		//上传凭证
		String uploadToken = Auth.create(QiNiuProperties.AK, QiNiuProperties.SK).uploadToken(QiNiuProperties.bucket);
		//上传文件
		try{
			uploadManager.put(io.getInputStream(),name,uploadToken,null,null);
		}
		catch (IOException e){
			throw new RuntimeException();
		}
		return QiNiuProperties.space+"/"+name;
	}
}
